"""
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    created by siyi.chen on '12/03/2025'
    comment: 消息通知相关
"""
from sqlalchemy import func
from sqlalchemy.dialects.mysql import VARCHAR, INTEGER, BOOLEAN, FLOAT, DATETIME, TIMESTAMP, DATE

from project.core.base import CustomModel, CustomList, CustomDict
from project.core.base import Column


class Message(CustomModel):
    """ 消息表
    """
    __tablename__ = "message"
    id = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True)
    third_party_id = Column(VARCHAR(50), nullable=False, server_default='', comment='第三方系统标识')
    third_party_msg_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='第三方系统消息唯一ID')
    type = Column(VARCHAR(30), nullable=False, server_default='', comment='消息类型')
    icon = Column(VARCHAR(200), nullable=False, server_default='', comment='图标')
    title = Column(VARCHAR(200), nullable=False, server_default='', comment='消息标题')
    voice = Column(VARCHAR(200), nullable=False, server_default='', comment='语音播报内容')
    content = Column(CustomDict, nullable=False, server_default='', comment='消息内容(JSON/文本)')
    expire_time = Column(DATETIME, nullable=False, server_default=func.now(), comment='消息有效期')
    create_time = Column(DATETIME, nullable=False, server_default=func.now())
    update_time = Column(TIMESTAMP, nullable=False, server_default=func.now(), onupdate=func.now())

class MessageDevice(CustomModel):
    """ 消息设备表
    """
    __tablename__ = "message_device"
    id = Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True)
    message_id = Column(INTEGER(unsigned=True), nullable=False, server_default='0', comment='消息id')
    dev_id = Column(VARCHAR(30), nullable=False, server_default='', comment='设备id')
    create_time = Column(DATETIME, nullable=False, server_default=func.now())
